package com.hgkx.util;

import javax.servlet.http.HttpServletRequest;

/**
 * 文件地址工具类
 */
public class FilePathUtil {
    /**
     * 物理地址转为访问地址
     * @param path
     * @param req
     * @return
     */
    public static String pathToUrl(String path , HttpServletRequest req){
        String url=req.getScheme() + "://" + req.getServerName() + ":" +
                req.getServerPort() + path.split(":")[1];
        return url;
    }

    /**
     * 判断路径最后一位是否有 "\"  或 "/" 没有的话就给补上
     * @param path
     * @return
     */
    public static String pathLast(String path){
        String lastSysPath=path.substring(path.length()-1);
        if (!"/".equals(lastSysPath)){
            if (!"\\".equals(lastSysPath)){
                path+="/";
            }
        }
        return path;
    }
}
